package com.example.john.myapplicationas;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private TabContainerView tabContainerView;

    private int[] iconImageArray, selectedIconImageArray;
    private Fragment[] fragments;

    private int[][] mIconArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initActionBar();
        tabContainerView = (TabContainerView) findViewById(R.id.tab_containerview_main);
        mIconArray = new int[][] {{R.drawable.icon_main, R.drawable.icon_main_selected}, {R.drawable.icon_work, R.drawable.icon_work_selected},
                {R.drawable.icon_app, R.drawable.icon_app_selected}, {R.drawable.icon_mine, R.drawable.icon_mine_selected}};

        iconImageArray = new int[]{R.drawable.icon_main, R.drawable.icon_work, R.drawable.icon_app, R.drawable.icon_mine};
        selectedIconImageArray = new int[]{R.drawable.icon_main_selected, R.drawable.icon_work_selected, R.drawable.icon_app_selected, R.drawable.icon_mine_selected};
        fragments = new Fragment[] {new MainFragment(), new WorkFragment(), new AppFragment(), new MineFragment()};

        tabContainerView = (TabContainerView) findViewById(R.id.tab_containerview_main);
        tabContainerView.setAdapter(new DefaultAdapter(this, fragments, getSupportFragmentManager(), getResources().getStringArray(R.array.titleArray),
                getResources().getColor(R.color.colorPrimary), iconImageArray, selectedIconImageArray));}
    private void initActionBar() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.tb_bar);
        //设置标题
        toolbar.setTitle("钟洪文");
        //设置标题颜色
        toolbar.setTitleTextColor(Color.WHITE);

        //设置log，标题左边的图标
        toolbar.setLogo(R.drawable.back);
        //设置副标题，title下面
        toolbar.setSubtitle("liyuanjing");
        toolbar.inflateMenu(R.menu.base_toolbar_menu);
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                return true;
            }
        });
        //设置回退按钮
        toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });



    }

}
